#include "gdt.h"
#include "tss.h"
//unsigned int ult_gdt_ocup=0x20;
unsigned int gdtLibre = (unsigned int) 7;
unsigned int gdtDisp = GDT_COUNT;

gdt_entry gdt[GDT_COUNT] = {
	/* Descriptor nulo*/
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	//Segmento de código de kernel (0x10)
	(gdt_entry){(unsigned short) 0xFFFF,(unsigned short) 0x0000,(unsigned char) 0x0,
				(unsigned char) 0xA,(unsigned char) 0x1,(unsigned char) 0x0,
				(unsigned char) 0x1,
				(unsigned char) 0xF,
				(unsigned char) 0x0,(unsigned char) 0x0,(unsigned char) 0x1,
				(unsigned char) 0x1,(unsigned char) 0x00},
	//segmento de datos de kernel (0x18)
	(gdt_entry){(unsigned short) 0xFFFF,(unsigned short) 0x0000,(unsigned char) 0x0,
				(unsigned char) 0x2,(unsigned char) 0x1,(unsigned char) 0x0,
				(unsigned char) 0x1,(unsigned char) 0xF,
				(unsigned char) 0x0,(unsigned char) 0x0,(unsigned char) 0x1,
				(unsigned char) 0x1,(unsigned char) 0x00},
	//Segmento de video (0x20)
	(gdt_entry){(unsigned short) 0x0F9F,(unsigned short) 0x8000,(unsigned char) 0x0B,
				(unsigned char) 0x2,(unsigned char) 0x1,(unsigned char) 0x0,
				(unsigned char) 0x1,(unsigned char) 0xF,
				(unsigned char) 0x0,(unsigned char) 0x0,(unsigned char) 0x0,
				(unsigned char) 0x0,(unsigned char) 0x00},
	//Segmento de Código de usuario	(0x28)
	(gdt_entry){(unsigned short) 0xFFFF,(unsigned short) 0x0000,(unsigned char) 0x0,
				//(unsigned char) 0xA,(unsigned char) 0x1,(unsigned char) 0x3,
				(unsigned char) 0xA,(unsigned char) 0x1,(unsigned char) 0x0,
				(unsigned char) 0x1,
				(unsigned char) 0xF,
				(unsigned char) 0x0,(unsigned char) 0x0,(unsigned char) 0x1,
				(unsigned char) 0x1,(unsigned char) 0x00},
	//Segmento de Datos de usuario (0x30)
	(gdt_entry){(unsigned short) 0xFFFF,(unsigned short) 0x0000,(unsigned char) 0x0,
				//(unsigned char) 0x2,(unsigned char) 0x1,(unsigned char) 0x3,
				(unsigned char) 0x2,(unsigned char) 0x1,(unsigned char) 0x0,
				(unsigned char) 0x1,(unsigned char) 0xF,
				(unsigned char) 0x0,(unsigned char) 0x0,(unsigned char) 0x1,
				(unsigned char) 0x1,(unsigned char) 0x00}

};
gdt_entry *obtener_sig_gdt_libre (){
	
	gdt_entry *entrada = (gdt_entry *)-1;
	if(gdtDisp--)
		entrada = &gdt[gdtLibre++];
		
	return entrada;

}
gdt_descriptor GDT_DESC = {sizeof(gdt)-1, (unsigned int)&gdt};
